var PrivateNoteMediator = Objs("view.PrivateNoteMediator",
	Mediator,
{

	initialize: function( name, viewComponent )
	{ 
		PrivateNoteMediator.$super.initialize.call( this, name, viewComponent );
    	this.VProxy = this.facade.retrieveProxy( ProxyNames.VEHICLE_PROXY );
		this.registerListeners();
		
		
	},
	registerListeners: function()
	{  
		var PrivateNotePageView = this.get();
		PrivateNotePageView.addEventListener( PrivateNotePage.ADD_PRIVATE_NOTE, this.addPrivateNotenHandler, this );

	},
	get: function()
	{
		return this.viewComponent;
	},
	listNotificationInterests: function()
	{
		return [
				NotificationNames.ADD_PNOTE_SUCCESS	,
				NotificationNames.ADDNEW_PNOTE_SUCCESS,
				NotificationNames.LIST_PRIVATE
				
		];
	},
    handleNotification: function( note )
	{ 
		
		switch (note.getName() )
		{ 
			
			case NotificationNames.ADD_PNOTE_SUCCESS:
				
				this.setpnotevalue();
				break;
			case NotificationNames.LIST_PRIVATE:
				currentnotes=note.getBody();
				this.setpnotevalue();
				break;
			case NotificationNames.ADDNEW_PNOTE_SUCCESS:
			
				privatenotesid.push(note.getBody().data)
				
				this.setaddnewpnotevalue(note.getBody());
				$('#privatenote-modal').modal('hide');
				break;	
		}
	},
	setaddnewpnotevalue:function(pnotesnew)
	{
		$("#list_private").append("<div class='commentBox'> <div style='border-bottom:solid 1px #CCC' id=messagehead ><strong>On " +pnotesnew.dateTime+ " " +pnotesnew.messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +pnotesnew.message+ "</div></div>")
	},
	addPrivateNotenHandler: function()
	{ 
	
		if(document.getElementById("private_text").value)
		{
			var cMessage=new Object();
			cMessage.message = document.getElementById("private_text").value;
			this.VProxy.addPrivateNote(cMessage);
			document.getElementById("private_text").value="";
			
		}
		else
		{
			alert("Private note box is empty. Please add some notes");
		}
	},
	setpnotevalue:function()
	{
		document.getElementById("privatenotemodel").innerHTML='';
		var prihtml=''
		for(var j=0;j<currentnotes.length;j++)
		{ 
			prihtml+="<div class='commentBox'> <div style='border-bottom:solid 1px #CCC' id=messagehead ><strong>On " +currentnotes[j].dateTime+ " " +currentnotes[j].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +currentnotes[j].message+ "</div></div>"; 
		}
		document.getElementById("privatenotemodel").innerHTML=prihtml;
	},
	
});

